package com.digital.smartgrow.controller.upscale;

import com.digital.smartgrow.common.advice.Result;
import com.digital.smartgrow.dto.upscale.ScaleItemPageDTO;
import com.digital.smartgrow.entity.upscale.ScaleItem;
import com.digital.smartgrow.service.upscale.ScaleItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 晋升指标项 前端控制器
 * </p>
 *
 * @author sunyuechao
 * @since 2022-07-12
 */
@Api(tags = "晋升指标项")
@RestController
@RequestMapping("${context.prefix}/syc/scaleItem")
public class ScaleItemController {

    @Autowired
    private ScaleItemService scaleItemService;

    @ApiOperation(value = "晋升指标项-分页查询")
    @PostMapping("/list")
    public Object getListByPage(@RequestBody ScaleItemPageDTO scaleItemPageDTO){
        return scaleItemService.getListByPage(scaleItemPageDTO);
    }

    @ApiOperation(value = "晋升指标项-详情")
    @GetMapping("/{id}")
    public Object getInfo(@PathVariable Integer id){
        if (id == null) return Result.fail("id不能为空");
        return scaleItemService.getInfo(id);
    }

    @ApiOperation(value = "晋升指标项-删除")
    @DeleteMapping("/{id}")
    public Object removeById(@PathVariable Integer id){
      if (id == null) return Result.fail("id不能为空");
      return scaleItemService.removeById(id);
    }
    @ApiOperation(value = "晋升指标项-新增")
    @PostMapping()
    public Object add( @RequestBody ScaleItem scaleItem){
       return scaleItemService.save(scaleItem);
    }

    @ApiOperation(value = "晋升指标项-编辑")
    @PutMapping()
    public Object edit(@RequestBody ScaleItem scaleItem){
    if (scaleItem==null||scaleItem.getId() == null)
       return Result.fail("id不能为空");
       return scaleItemService.updateById(scaleItem);
    }
}
